import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Demo5 {
    public static void main(String[] args) {
//
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入文件路径");
        String rootDirPath = scanner.next();
        File rootDir = new File(rootDirPath);
        if(!rootDir.isDirectory()){
            System.out.println("您输入的根目录不窜在或者不是目录");
            return;
        }
        System.out.println("请输入要找出的文件名中的字符");
        String token = scanner.next();
        List<File> result = new ArrayList<>();


    }
    private static void scanDirWithContent(File rootDir,String token,List<File> result) throws IOException {
        File[] files = rootDir.listFiles();
        if(files == null || files.length == 0){
            return;
        }
        for (File file: files) {
            if(file.isDirectory()){
                scanDirWithContent(file,token,result);
            }else {
                if(isContentContains(file,token)){
                    result.add(file.getAbsoluteFile());
                }
            }
        }
    }

    private static boolean isContentContains(File file, String token) throws IOException {
        StringBuilder sb = new StringBuilder();
        try(InputStream is = new FileInputStream(file);
        Scanner scanner = new Scanner(is,"UTF-8")){
            while (scanner.hasNext()){
                sb.append(scanner.next());
                sb.append("\n\r");
            }
        }
        return sb.indexOf(token) != -1;
    }
}
